package com.xiangyi.teachingsystem.entity.po;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.xiangyi.teachingsystem.validation.groups.AdminOperUser;
import com.xiangyi.teachingsystem.validation.groups.Login;
import com.xiangyi.teachingsystem.validation.groups.Register;
import com.xiangyi.teachingsystem.validation.groups.UserInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.*;
import java.sql.Timestamp;

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class User {
    //标识id
    @TableId(value = "id", type = IdType.AUTO)
    @NotNull(message = "id不能为空",groups = {UserInfo.class})
    private Integer id;
    //手机号
    @Pattern(regexp = "^1[345789]\\d{9}$", message = "手机号格式有误",groups = {Register.class,Login.class, AdminOperUser.class})
    private String phoneNum;
    //密码
    @NotNull(message = "密码不能为空", groups = {Register.class,Login.class})
    @Length(min = 8, max = 16, message = "密码长度在6-20位之间", groups = {Register.class})
    private String passWd;
    //姓名
    @NotBlank(message = "姓名信息不能为空",groups = {UserInfo.class})
    private String name;
    //学院
    @NotBlank(message = "学院信息不能为空",groups = {UserInfo.class})
    private String college;
    //年级
    private String grade;
    //班级
    private String className;
    //学工号
    @NotBlank(message = "工号信息不能为空",groups = {UserInfo.class})
    private String jobNum;
    //性别
    private String sex;
    //头像url
    private String headUrl;
    //上次登录ip
    @NotNull(message = "登录ip信息不能为空",groups = {Login.class})
    private String lastIp;
    //上次登录时间
    @NotNull(message = "登录时间信息不能为空",groups = {Login.class})
    private Timestamp lastTime;
    //个性签名
    private String signature;
    //学校
    private String school;
    @NotNull(message = "教师标识teacherSign应为0或1",groups = {Register.class})
    //教师标识
    private Boolean teacherSign;
    //管理员标识
    private Boolean adminSign;
    @TableField(exist = false)
    private String city;

    //序列化的时候取值忽略这个字，等于返回的时候忽略这个字段
    @JsonIgnore
    public String getPassWd() {
        return passWd;
    }

    //取参数的时候不忽略，等于入参的时候不忽略
    @JsonProperty
    public void setPassWd(String passWd) {
        this.passWd = passWd;
    }
}
